<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <style type="text/css">
        .header {
            padding: 2.5rem 0.5rem 2rem 0.5rem;
        }
    </style>
    <script language=JavaScript>
        //计算保留多少位小数，后面参数为小数点位数
        function fomatFloat(src, pos) {
            return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
        }
        function IsDigit(cCheck) {
            return ((('0' <= cCheck) && (cCheck <= '9')) || cCheck == '.' || cCheck == '-');
        }
        function checklineInput() {
            var full_bz_num = document.getElementById("maxvaluea");
            var zero_bz_num = document.getElementById("maxvalueb");
            var full_xs_num = document.getElementById("maxvaluec");
            var zero_xs_num = document.getElementById("maxvalued");
            if (full_bz_num.value == "") {
                alert("请输入满度标准值");
                full_bz_num.focus();
                return false;
            }
            if (CheckNum(full_bz_num.value, "满度标准值只能输入数字格式！", full_bz_num) == false)
                return false;

            if (zero_bz_num.value == "") {
                alert("请输入零点标准值");
                zero_bz_num.focus();
                return false;
            }
            if (CheckNum(zero_bz_num.value, "零点标准值只能输入数字格式！", zero_bz_num) == false)
                return false;

            if (full_xs_num.value == "") {
                alert("请输入满度显示值");
                full_xs_num.focus();
                return false;
            }
            if (CheckNum(full_xs_num.value, "满度显示值只能输入数字格式！", full_xs_num) == false)
                return false;

            if (zero_xs_num.value == "") {
                alert("请输入零点显示值");
                zero_xs_num.focus();
                return false;
            }
            if (CheckNum(zero_xs_num.value, "零点显示值只能输入数字格式！", zero_xs_num) == false)
                return false;
        }


        function CheckNum(charValue, alertValue, obj) {
            for (var iIndex = 0; iIndex < charValue.length; iIndex++) {
                var cCheck = charValue.charAt(iIndex);
                if (!IsDigit(cCheck)) {
                    alert(alertValue);
                    obj.focus();
                    return false;
                }
            }
        }
        function reset(){
            var full_bz_num = document.getElementById("maxvaluea");
            var zero_bz_num = document.getElementById("maxvalueb");
            var full_xs_num = document.getElementById("maxvaluec");
            var zero_xs_num = document.getElementById("maxvalued");
            var coff_num = document.getElementById("maxvaluee");
            var zero_num = document.getElementById("maxvaluef");
            full_bz_num.value="";
            zero_bz_num.value="";
            full_xs_num.value="";
            zero_xs_num.value="";
            coff_num.value="";
            zero_num.value="";
        }
        function liner_calculation() {

            var full_bz_num = document.getElementById("maxvaluea");
            var zero_bz_num = document.getElementById("maxvalueb");
            var full_xs_num = document.getElementById("maxvaluec");
            var zero_xs_num = document.getElementById("maxvalued");
            var coff_num = document.getElementById("maxvaluee");
            var zero_num = document.getElementById("maxvaluef");
            //检查输入
            if (checklineInput() == false) return;
            var full_bz = 0.000, zero_bz = 0.000, full_xs = 0.000, zero_xs = 0.000;
            var coff_n = 0.0000;
            var zero_n = 0.000;
            //给各个变量赋值
            full_bz = full_bz_num.value;
            zero_bz = zero_bz_num.value;
            full_xs = full_xs_num.value;
            zero_xs = zero_xs_num.value;
            // 开始计算
            // 系数=（标准满度-标准零点）/（显示满度-显示零点）
            // 零点=标准零点-显示零点*系数
            coff_n = (full_bz - zero_bz) / (full_xs - zero_xs);
            zero_n = zero_bz - zero_xs * coff_n;
            coff_num.value = fomatFloat(coff_n, 4);
            zero_num.value = fomatFloat(zero_n, 4);
        }
    </script>
</head>

<body>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-header">线性校准计算器</li>
            <li class="aui-list-header"> 1.请输入标准信息值</li>

            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        满度标准值
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="Number" id="maxvaluea">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        零度标准值
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="Number" id="maxvalueb">
                    </div>
                </div>
            </li>
            <li class="aui-list-header"> 2.请输入显示值信息</li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        满度显示值
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="Number" id="maxvaluec">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        零度显示值
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="Number" id="maxvalued">
                    </div>
                </div>
            </li>
            <li class="aui-list-header"> 计算结果</li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        系数
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="Number" id="maxvaluee">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        零点
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="Number" id="maxvaluef">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner aui-list-item-center aui-list-item-btn">
                    <div class="aui-btn aui-btn-info aui-margin-r-5" onclick="liner_calculation()">提交</div>
                    <div class="aui-btn aui-btn-danger aui-margin-l-5" onclick="reset()">重置</div>
                </div>
            </li>
        </ul>
    </div>

</body>

</html>